﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeGame_Roman
{
    public class OptimizedRenderer : GameRender
    {
        private bool isFieldRendered = false;

        public override void RenderField(GameField field)
        {
            if (!isFieldRendered)
            {
                base.RenderField(field);
                this.isFieldRendered = true;
           }
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            for (int i = 0; i < field.width; i++)// перерисовывает при каждом тике правую сторону поля
            {                                    
                Console.SetCursorPosition(field.lenght - 1, i);
                Console.Write('║');

                if (i == field.width - 1)
                {
                    Console.SetCursorPosition(field.lenght - 1, 0);
                    Console.Write('╗');


                    Console.SetCursorPosition(field.lenght - 1, field.width - 1);
                    Console.Write('╝');

                }
            }
           
        }
        
        public override void RenderSnake(Snake snake)
        {
            base.RenderSnake(snake);
            Console.SetCursorPosition(snake.piesesOfSnake[snake.lenghtOfSnake - 1].X, snake.piesesOfSnake[snake.lenghtOfSnake - 1].Y);
           
            
            //Console.WriteLine(snake.piesesOfSnake.Remove[snake.lenghtOfSnake - 1]);
            
            Console.Write(" ");
           

        }
    }
}
